package com.zjj.day2.test5;

import java.util.Random;
/**
 * @author zhoujunjie
 * @desc TODO
 * @date 2025/4/18
 */
import java.util.ArrayList;
import java.util.List;
import java.util.Random;

class Hero {
    private String name;
    private int level;
    private int blood;
    private int power;
    private int defence;
    private String kind;
    private List<Equip> equips;

    public Hero(String name, int level, int blood, int power, int defence, String kind) {
        this.name = name;
        this.level = level;
        this.blood = blood;
        this.power = power;
        this.defence = defence;
        this.kind = kind;
        this.equips = new ArrayList<>();
    }

    public void attack(Monster m) {
        Random random = new Random();
        int critical = random.nextInt(100);
        int totalPower = power;
        if (critical > 75) {
            totalPower += 20;
            System.out.println(name + " 打出了暴击！");
        }
        int damage = totalPower - m.getDefence();
        if (damage > 0) {
            m.setBlood(m.getBlood() - damage);
            System.out.println(name + " 攻击了 " + m.getName() + "，造成了 " + damage + " 点伤害。");
        } else {
            System.out.println(name + " 攻击了 " + m.getName() + "，但未造成伤害。");
        }
    }

    public boolean isDead() {
        return blood <= 0;
    }

    public void addEquip(Equip e) {
        if (equips.size() < 3) {
            equips.add(e);
            power += e.getPower();
            defence += e.getDefence();
            System.out.println(name + " 装备了 " + e.getName());
        } else {
            System.out.println(name + " 装备已满，无法再装备 " + e.getName());
        }
    }

    public void show() {
        System.out.println("英雄信息：");
        System.out.println("昵称：" + name);
        System.out.println("等级：" + level);
        System.out.println("血量：" + blood);
        System.out.println("攻击力：" + power);
        System.out.println("防御力：" + defence);
        System.out.println("种族：" + kind);
        System.out.println("装备：");
        for (Equip equip : equips) {
            equip.show();
        }
    }

    public int getBlood() {
        return blood;
    }

    public void setBlood(int blood) {
        this.blood = blood;
    }

    public int getDefence() {
        return defence;
    }

    public String getName() {
        return name;
    }
}